﻿	      <?php include("conn.php");
             mysql_query('SET NAMES UTF8'); 

	  

class MyPrizeBean
{
	public $title;
	public $price;
	public $images;
	public $yuanjia;
	public $goodsid;
	public $reply;
	public $xihuan;
	public $summary;
public $juli;
public $pings;
public $xiaoliang;
	function __construct($title,$price,$images,$yuanjia,$goodsid,$reply,$xihuan,$summary,$juli,$pings,$xiaoliang)
	{
		$this->title      = $title;
		$this->price = $price;
		$this->images     = $images;
		$this->yuanjia      = $yuanjia;
		$this->goodsid    = $goodsid;
		$this->reply    = $reply;
		$this->xihuan    = $xihuan;
		$this->summary    = $summary;
		$this->juli    = $juli;
		$this->pings    = $pings;
		$this->xiaoliang    = $xiaoliang;
	}
}



if($_REQUEST['page']!="")
{
$de=$_REQUEST['page']*$_REQUEST['pagesize'];
$size=$_REQUEST['pagesize'];
}

else
{
$de=0;
$size=5;
}


     $sj=1;
    

    

	 if($_REQUEST[city]!="")
	{

  $rert30=mysql_query("select *from goods  where city = '".$_REQUEST[city]."' and  shangjia='".$sj."'  and tejia ='".$sj."'  order by goodsid desc limit $de,$size");
     } 
	 
	 else
	 
	 {
	 $rert30=mysql_query("select *from goods   where   shangjia='".$sj."' and tejia ='".$sj."'  order by goodsid desc limit $de,$size");
	 }
	 

	
	$prize = array();
	
	while($rowf=mysql_fetch_array($rert30)){
	
	
	$counts=mysql_query("select SUM(service) from goodsreply  where   goodsid ='".$rowf['goodsid']."'");

//评论数
$rss=mysql_fetch_array($counts);
$sum=$rss[0];


$count=mysql_query("select count(*) from goodsreply  where   goodsid ='".$rowf['goodsid']."'");

//评论数
$rs=mysql_fetch_array($count);
$totalNumber=$rs[0];
if($totalNumber!=0)
{
$sum=$totalNumber;
$ping=round(($sum/$totalNumber),2);
}
else
{
$ping=5;

}
	
	 if ($ping < 2) {
                            $pinfen = "<span></span><span class='empty'></span><span class='empty'></span><span class='empty'></span><span class='empty'></span>";
                        } 
						
						 else if ($ping < 3 and $ping > 2) {
                            $pinfen = "<span></span><span></span><span class='empty'></span><span class='empty'></span><span class='empty'></span>";
                        } 
						
						 else if ($ping < 4 and $ping > 3) {
                           $pinfen = "<span></span><span></span><span ></span><span class='empty'></span><span class='empty'></span>";
                        }
						 else if ($ping < 5 and $ping > 4) {
                           $pinfen = "<span></span><span></span><span ></span><span></span><span class='empty'></span>";
                        }
						 else  {
                           $pinfen = "<span></span><span></span><span ></span><span ></span><span ></span>";
                        }
						
		$ime=$rowf[images];
				$de = array();
				$de=explode("," ,$ime);
				$images=$de[0];
	
	           $julis=0.12;
			   
			   if(strlen($rowf['title'])>14)
		
		{
		
		$NAMES=mb_substr($rowf['title'], 0,14,"UTF-8");
		}
		else
		{
		$NAMES=$rowf['title'];
		}
		
		if(strlen($rowf['summary'])>30)
		
		{
		
		$summarys=mb_substr($rowf['summary'], 0,30,"UTF-8");
		}
		else
		{
		$summarys=$rowf['summary'];
		}
		

			$prize[] = new MyPrizeBean($NAMES,$rowf['price'],$images,$rowf['yuanjia'],$rowf['goodsid'],$totalNumber,$rowf['xihuan'],$summarys, $julis,$pinfen,$rowf['xiaoliang']);
		
	}

echo json_encode($prize);


?>